using System;
using System.Collections.Generic;
using System.Text;

namespace A4G.Core
{
	public interface IGapMethodProvider
	{
		double CalculateGapPenalty(int gaps);
	}

	public class PolinomialGapMethodProvider : IGapMethodProvider
	{
		public PolinomialGapMethodProvider(double constant)
			: this(new double[] {constant})
		{
		}

		public PolinomialGapMethodProvider(double[] constants)
		{
			_constants = constants;
		}

		private readonly double[] _constants;
		public double[] Constants
		{
			get { return _constants; }
		}

		#region IGapMethod Members
		public double CalculateGapPenalty(int gaps)
		{
			double result = 0;
			int termCount = 0;
			foreach (double constant in Constants)
			{
				result += constant * Math.Pow(gaps, termCount);
			}

			if (result > -1.0)
			{
				result = -1.0;
			}

			return result;
		}
		#endregion
	}
}
